home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 34 / Amiga Format CD34 (1998-11-20)(Future Publishing)(GB)[!][Christmas issue].iso / -seriously_amiga- / programming / c / mesa-2.6 / src-glu / nurbs.c < prev    next >
C/C++ Source or Header  |  1998-10-01  |  21KB  |  675 lines

  1. /* $Id: nurbs.c,v 1.11 1998/02/07 14:29:11 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.6
  6.  * Copyright (C) 1995-1997  Brian Paul
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25.  * nurbs.c
  26.  *
  27.  * Version 1.0  27 Jun 1998
  28.  * by Jarno van der Linden
  29.  * jarno@kcbbs.gen.nz
  30.  *
  31.  * File created from nurbs.c ver 1.11 and glu.h ver 1.9 using GenProtos
  32.  *
  33.  */
  34.  
  35.  
  36. /*
  37.  * NURBS implementation written by Bogdan Sikorski (bogdan@cira.it)
  38.  * See README2 for more info.
  39.  */
  40.  
  41. #ifdef PC_HEADER
  42. #include "all.h"
  43. #else
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include "gluP.h"
  47. #include "nurbs.h"
  48. #endif
  49.  
  50.  
  51. void
  52. call_user_error( GLUnurbsObj *nobj, GLenum error )
  53. {
  54.     nobj->error=error;
  55.     if(nobj->error_callback != NULL) {
  56.         (*(nobj->error_callback))(error);
  57.     }
  58.     else {
  59.        printf("NURBS error %d %s\n", error, gluErrorString(error) );
  60.     }
  61. }
  62.  
  63.  
  64.  
  65. __asm __saveds GLUnurbsObj * APIENTRY gluNewNurbsRenderer( void )
  66. {
  67.    GLUnurbsObj *n;
  68.    GLfloat tmp_viewport[4];
  69.    GLint i,j;
  70.  
  71.    n = (GLUnurbsObj *) malloc( sizeof(GLUnurbsObj) );
  72.    if (n) {
  73.       /* init */
  74.       n->culling=GL_FALSE;
  75.       n->nurbs_type=GLU_NURBS_NONE;
  76.       n->error=GLU_NO_ERROR;
  77.       n->error_callback=NULL;
  78.       n->auto_load_matrix=GL_TRUE;
  79.       n->sampling_tolerance=50.0;
  80.       n->parametric_tolerance=0.5;
  81.       n->u_step = n->v_step = 100;
  82.       n->sampling_method = GLU_PATH_LENGTH;
  83.       n->display_mode=GLU_FILL;
  84.       /* in case the user doesn't supply the sampling matrices */
  85.       /* set projection and modelview to identity */
  86.       for(i=0;i<4;i++)
  87.           for(j=0;j<4;j++)
  88.               if(i==j)
  89.               {
  90.                 n->sampling_matrices.model[i*4+j]=1.0;
  91.                 n->sampling_matrices.proj[i*4+j]=1.0;
  92.             }
  93.             else
  94.               {
  95.                 n->sampling_matrices.model[i*4+j]=0.0;
  96.                 n->sampling_matrices.proj[i*4+j]=0.0;
  97.             }
  98.       /* and set the viewport sampling matrix to current ciewport */
  99.       glGetFloatv(GL_VIEWPORT,tmp_viewport);
  100.       for(i=0;i<4;i++)
  101.           n->sampling_matrices.viewport[i]=tmp_viewport[i];
  102.       n->trim=NULL;
  103.    }
  104.    return n;
  105. }
  106.  
  107.  
  108.  
  109. __asm __saveds void APIENTRY gluDeleteNurbsRenderer( register __a0 GLUnurbsObj *nobj )
  110. {
  111.    if (nobj) {
  112.       free( nobj );
  113.    }
  114. }
  115.  
  116.  
  117.  
  118. __asm __saveds void APIENTRY gluLoadSamplingMatrices( register __a0 GLUnurbsObj *nobj,
  119.                                                       register __a1 const GLfloat modelMatrix[16],
  120.                                                       register __a2 const GLfloat projMatrix[16],
  121.                                                       register __a3 const GLint viewport[4] )
  122. {
  123.     GLint    i;
  124.  
  125.     for(i=0;i<16;i++)
  126.     {
  127.         nobj->sampling_matrices.model[i]=modelMatrix[i];
  128.         nobj->sampling_matrices.proj[i]=projMatrix[i];
  129.     }
  130.     for(i=0;i<4;i++)
  131.         nobj->sampling_matrices.viewport[i]=viewport[i];
  132. }
  133.  
  134.  
  135. __asm __saveds void APIENTRY gluNurbsProperty( register __a0 GLUnurbsObj *nobj, register __d0 GLenum property, register __fp0 GLfloat value )
  136. {
  137.    GLenum val;
  138.  
  139.    switch (property) {
  140.       case GLU_SAMPLING_TOLERANCE:
  141.            if(value <= 0.0)
  142.            {
  143.                call_user_error(nobj,GLU_INVALID_VALUE);
  144.                return;
  145.          }
  146.          nobj->sampling_tolerance=value;
  147.          break;
  148.       case GLU_PARAMETRIC_TOLERANCE:
  149.            if(value <= 0.0)
  150.            {
  151.                call_user_error(nobj,GLU_INVALID_VALUE);
  152.                return;
  153.          }
  154.          nobj->parametric_tolerance=value;
  155.          break;
  156.       case GLU_U_STEP:
  157.            if(value <= 0.0)
  158.            {
  159.                call_user_error(nobj,GLU_INVALID_VALUE);
  160.                return;
  161.          }
  162.          nobj->u_step=(GLint)value;
  163.          break;
  164.       case GLU_V_STEP:
  165.            if(value <= 0.0)
  166.            {
  167.                call_user_error(nobj,GLU_INVALID_VALUE);
  168.                return;
  169.          }
  170.          nobj->v_step=(GLint)value;
  171.          break;
  172.       case GLU_SAMPLING_METHOD:
  173.          val = (GLenum)value;
  174.          if(val!=GLU_PATH_LENGTH && val!=GLU_PARAMETRIC_ERROR && val!=GLU_DOMAIN_DISTANCE)
  175.          {
  176.              call_user_error(nobj,GLU_INVALID_ENUM);
  177.              return;
  178.          }
  179.          nobj->sampling_method=val;
  180.          break;
  181.       case GLU_DISPLAY_MODE:
  182.          val=(GLenum)value;
  183.          if(val!=GLU_FILL && val!=GLU_OUTLINE_POLYGON && val!=GLU_OUTLINE_PATCH)
  184.          {
  185.              call_user_error(nobj,GLU_INVALID_ENUM);
  186.              return;
  187.          }
  188.          if(nobj->nurbs_type==GLU_NURBS_CURVE)
  189.          {
  190.              call_user_error(nobj,GLU_NURBS_ERROR26);
  191.              return;
  192.          }
  193.          nobj->display_mode=val;
  194. if(val==GLU_OUTLINE_PATCH)
  195.     fprintf(stderr,"NURBS, for the moment, can display only in POLYGON mode\n");
  196.          break;
  197.       case GLU_CULLING:
  198.          val=(GLenum)value;
  199.          if(val!=GL_TRUE && val!=GL_FALSE)
  200.          {
  201.              call_user_error(nobj,GLU_INVALID_ENUM);
  202.              return;
  203.          }
  204.          nobj->culling = (GLboolean) value;
  205.          break;
  206.       case GLU_AUTO_LOAD_MATRIX:
  207.          val=(GLenum)value;
  208.          if(val!=GL_TRUE && val!=GL_FALSE)
  209.          {
  210.              call_user_error(nobj,GLU_INVALID_ENUM);
  211.              return;
  212.          }
  213.          nobj->auto_load_matrix = (GLboolean) value;
  214.          break;
  215.       default:
  216.          call_user_error(nobj,GLU_NURBS_ERROR26);
  217.    }
  218. }
  219.  
  220.  
  221. __asm __saveds void APIENTRY gluGetNurbsProperty( register __a0 GLUnurbsObj *nobj, register __d0 GLenum property, register __a1 GLfloat *value )
  222. {
  223.    switch (property) {
  224.       case GLU_SAMPLING_TOLERANCE:
  225.          *value = nobj->sampling_tolerance;
  226.          break;
  227.       case GLU_DISPLAY_MODE:
  228.          *value = (GLfloat) (GLint) nobj->display_mode;
  229.          break;
  230.       case GLU_CULLING:
  231.          *value = nobj->culling ? 1.0 : 0.0;
  232.          break;
  233.       case GLU_AUTO_LOAD_MATRIX:
  234.          *value = nobj->auto_load_matrix ? 1.0 : 0.0;
  235.          break;
  236.       default:
  237.          call_user_error(nobj,GLU_INVALID_ENUM);
  238.    }
  239. }
  240.  
  241.  
  242.  
  243. __asm __saveds void APIENTRY gluBeginCurve( register __a0 GLUnurbsObj *nobj )
  244. {
  245.     if(nobj->nurbs_type==GLU_NURBS_CURVE)
  246.     {
  247.         call_user_error(nobj,GLU_NURBS_ERROR6);
  248.         return;
  249.     }
  250.     nobj->nurbs_type=GLU_NURBS_CURVE;
  251.     nobj->curve.geom.type=GLU_INVALID_ENUM;
  252.     nobj->curve.color.type=GLU_INVALID_ENUM;
  253.     nobj->curve.texture.type=GLU_INVALID_ENUM;
  254.     nobj->curve.normal.type=GLU_INVALID_ENUM;
  255. }
  256.  
  257.  
  258. __asm __saveds void APIENTRY gluEndCurve( register __a0 GLUnurbsObj * nobj )
  259. {
  260.     if(nobj->nurbs_type==GLU_NURBS_NONE)
  261.     {
  262.         call_user_error(nobj,GLU_NURBS_ERROR7);
  263.         return;
  264.     }
  265.     if(nobj->curve.geom.type==GLU_INVALID_ENUM)
  266.     {
  267.         call_user_error(nobj,GLU_NURBS_ERROR8);
  268.         nobj->nurbs_type=GLU_NURBS_NONE;
  269.         return;
  270.     }
  271.     glPushAttrib( (GLbitfield) (GL_EVAL_BIT | GL_ENABLE_BIT) );
  272.     glDisable(GL_MAP1_VERTEX_3);
  273.     glDisable(GL_MAP1_VERTEX_4);
  274.     glDisable(GL_MAP1_INDEX);
  275.     glDisable(GL_MAP1_COLOR_4);
  276.     glDisable(GL_MAP1_NORMAL);
  277.     glDisable(GL_MAP1_TEXTURE_COORD_1);
  278.     glDisable(GL_MAP1_TEXTURE_COORD_2);
  279.     glDisable(GL_MAP1_TEXTURE_COORD_3);
  280.     glDisable(GL_MAP1_TEXTURE_COORD_4);
  281.     glDisable(GL_MAP2_VERTEX_3);
  282.     glDisable(GL_MAP2_VERTEX_4);
  283.     glDisable(GL_MAP2_INDEX);
  284.     glDisable(GL_MAP2_COLOR_4);
  285.     glDisable(GL_MAP2_NORMAL);
  286.     glDisable(GL_MAP2_TEXTURE_COORD_1);
  287.     glDisable(GL_MAP2_TEXTURE_COORD_2);
  288.     glDisable(GL_MAP2_TEXTURE_COORD_3);
  289.     glDisable(GL_MAP2_TEXTURE_COORD_4);
  290.     do_nurbs_curve(nobj);
  291.     glPo